<template>
  <div class="count">
    <h2>当前求和为: {{ sum }}，放大十倍为：{{ bigSum }}</h2>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add">加</button>
    <button @click="minus">减</button>
  </div>
</template>

<script setup lang="ts" name="Count">
import { ref } from 'vue'
import { useCountStore } from '@/store/count'
import { storeToRefs } from 'pinia'

const countStore = useCountStore()
const { sum, bigSum } = storeToRefs(countStore)

let n = ref(1)

function add() {
  // 第一种修改方式
  // countStore.sum += 1

  // 第二种修改方式
  /* countStore.$patch({
      sum:888,
      school: '尚硅谷222',
      address:'北京2222'
    }) */

  // 第三种修改方式
  countStore.increment(n.value)
}
function minus() {
  sum.value -= n.value
}
</script>

<style scoped>
.count {
  background-color: skyblue;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}
</style>
